home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / fssharea / frmclien.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-19  |  6.1 KB  |  186 lines

  1. VERSION 5.00
  2. Begin VB.Form frmClient 
  3.    Caption         =   "Client"
  4.    ClientHeight    =   2940
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5865
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2940
  10.    ScaleWidth      =   5865
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "&Client"
  14.       Height          =   345
  15.       Left            =   4530
  16.       TabIndex        =   6
  17.       Top             =   480
  18.       Width           =   1215
  19.    End
  20.    Begin VB.TextBox Text1 
  21.       Height          =   435
  22.       Left            =   1950
  23.       TabIndex        =   0
  24.       Top             =   1500
  25.       Width           =   2235
  26.    End
  27.    Begin VB.CommandButton cmdOK 
  28.       Caption         =   "OK"
  29.       Height          =   315
  30.       Left            =   4530
  31.       TabIndex        =   1
  32.       Top             =   90
  33.       Width           =   1200
  34.    End
  35.    Begin VB.Label Label4 
  36.       Height          =   1095
  37.       Left            =   150
  38.       TabIndex        =   5
  39.       Top             =   1500
  40.       Width           =   1635
  41.    End
  42.    Begin VB.Label Label3 
  43.       Caption         =   "Data saved by the server:"
  44.       Height          =   405
  45.       Left            =   150
  46.       TabIndex        =   4
  47.       Top             =   180
  48.       Width           =   1485
  49.    End
  50.    Begin VB.Label Label2 
  51.       BorderStyle     =   1  'Fixed Single
  52.       Height          =   345
  53.       Left            =   1950
  54.       TabIndex        =   3
  55.       Top             =   600
  56.       Width           =   2205
  57.    End
  58.    Begin VB.Label Label1 
  59.       BorderStyle     =   1  'Fixed Single
  60.       Height          =   315
  61.       Left            =   1950
  62.       TabIndex        =   2
  63.       Top             =   180
  64.       Width           =   2205
  65.    End
  66. Attribute VB_Name = "frmClient"
  67. Attribute VB_GlobalNameSpace = False
  68. Attribute VB_Creatable = False
  69. Attribute VB_PredeclaredId = True
  70. Attribute VB_Exposed = False
  71. ' *******************************************************************
  72. ' ** This example was created by Fishhead Software, 1998
  73. ' *******************************************************************
  74. Option Explicit
  75. Private m_Share As fsShare
  76. Private m_Handle As Long
  77. 'Private WithEvents m_Events As fsEvents  ' ** Needed only if want to receive messages
  78. Private Sub cmdOK_Click()
  79.     Unload Me
  80. End Sub
  81. Private Sub Command1_Click()
  82.     If GetServer <> fsSHHNoServerHandle Then
  83.         
  84.         ' ** Ensure the next client will attach
  85.         ' ** to the same server;
  86.         m_Share.SetDefaultServer
  87.         Shell "client.exe", vbNormalFocus
  88.         
  89.     End If
  90. End Sub
  91. Private Sub Form_Initialize()
  92.     Set m_Share = New fsShare
  93.    ' Set m_Events = m_Share.fsEvents  ' Only needed if we want the messages
  94.     ' ** Coonect to the server as client;
  95.     m_Handle = m_Share.ConnectClient("my server", "my client")
  96. End Sub
  97. Private Sub Form_Load()
  98.     On Error Resume Next
  99.     Dim f As Object
  100.     Dim s As Variant
  101.     Dim i As Long
  102.      
  103.     If m_Share.GetServerHandle <> fsSHHNoServerHandle Then
  104.         ' ** Determine if the server saved its width and height;
  105.         i = m_Share.GetIndex("pos")
  106.         If i Then
  107.             ' ** It did, now position the client accordingly.
  108.             ' ** Returns an array, s(1) = Width and s(2) = Height;
  109.             s = m_Share.GetDataByIndex(i)
  110.             Me.Move s(1), s(2)
  111.         End If
  112.         
  113.         ' ** Get the data saved by the server;
  114.         Label1.Caption = m_Share.GetData("Company")
  115.         Label2.Caption = m_Share.GetData("Product")
  116.         
  117.         ' ** You can get saved objects;
  118.         Set f = m_Share.GetObject("server form")
  119.         
  120.     End If
  121.     Label4.Caption = "Edit me.  Add some text in the text box and watch how the server gets updated."
  122. End Sub
  123. Private Sub Form_Terminate()
  124.     ' ** Remove the connection to free up the data;
  125.     m_Share.DisconnectClient
  126. End Sub
  127. Private Sub Text1_Change()
  128.     Dim Handle As Long
  129.       
  130.     ' ** Verify if the client is attached to a server;
  131.     Handle = GetServer
  132.     If Handle <> fsSHHNoServerHandle Then
  133.         ' ** Echo the changes to the server text
  134.         ' ** window using our own defined message;
  135.         Call m_Share.FireDataMessage(Handle, fsSHFMUser + 1, Text1.Text)
  136.     End If
  137. End Sub
  138. ' **********************************************
  139. ' ** This routine will return the server handle
  140. ' ** and load the server if it is not present;
  141. ' **********************************************
  142. Private Function GetServer() As Long
  143.     On Error GoTo ErrorHandler
  144.     Dim ServerHandle As Long
  145.     Dim t As Long
  146.     ' ** Gets the server handle or returns
  147.     ' ** no handle;
  148.     ServerHandle = m_Share.GetServerHandle
  149.     If ServerHandle = fsSHHNoServerHandle Then
  150.         
  151.         ' ** Start the server;
  152.         Shell "Server.exe", vbNormalNoFocus
  153.         
  154.         ' ** Wait until server handle gets set;
  155.         Do
  156.             DoEvents
  157.             ServerHandle = m_Share.GetServerHandle
  158.         Loop While ServerHandle = fsSHHNoServerHandle
  159.         
  160. Retry:
  161.         ' ** Keep on retrying until server is fully loaded;
  162.         If ServerHandle <> fsSHHNoServerHandle Then
  163.             ' *********************************************
  164.             ' ** These commands will error out if the
  165.             ' ** server has not save them in its form load;
  166.             ' *********************************************
  167.             Label1.Caption = m_Share.GetData("Company")
  168.             Label2.Caption = m_Share.GetData("Product")
  169.         End If
  170.         
  171.     End If
  172. ExitFunc:
  173.     GetServer = ServerHandle
  174.     Exit Function
  175. ErrorHandler:
  176.     ' ****************************************
  177.     ' ** Keep on trying until item is set,
  178.     ' ** otherwise some other error occurred;
  179.     ' ****************************************
  180.     If Err.Number = fsSHErrItemNotFound Then
  181.         Resume Retry
  182.     Else
  183.         Resume ExitFunc
  184.     End If
  185. End Function
  186.